package com.miao.im.biz;

import com.miao.im.common.Message;
import com.miao.im.common.annotation.MessageCommand;
import com.miao.im.common.enums.Command;
import com.miao.im.model.OfflineMsgAckRequestModel;
import com.miao.im.server.session.SessionContext;
import com.miao.im.service.message.OfflineMessageManager;
import com.miao.im.support.handler.AbstractMessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/3/20 21:39
 * @Description:
 */
@Component
@MessageCommand(Command.OFFLINE_MSG_ACK)
@Slf4j
public class OfflineMsgAckRequestHandler extends AbstractMessageHandler<OfflineMsgAckRequestModel.OfflineMsgAckRequest> {
    @Autowired
    private OfflineMessageManager offlineMessageManager;

    @Override
    protected void doRead(OfflineMsgAckRequestModel.OfflineMsgAckRequest body, Message message) {

    }

    @Override
    protected Mono<Void> doDispatch(OfflineMsgAckRequestModel.OfflineMsgAckRequest body, Message message, SessionContext sessionContext) {
        log.info("收到离线消息ack");
        return offlineMessageManager.deletePersonalRange(Long.parseLong(sessionContext.getUserInfo().getUserId()),
                body.getTargetId(), body.getTargetType(),
                body.getLastTimestamp(), System.currentTimeMillis());
    }
}
